<template>
	<view>
		<uni-forms style="width: 500rpx; margin: 50rpx auto 0rpx;">
			<uni-forms-item>
				<uni-easyinput v-model="usernameData.username" placeholder="昵称" />
			</uni-forms-item>
		</uni-forms>
		
		<view style="width: 150rpx; margin: 0 auto;">
			<u-button @click="submit">提交</u-button>
		</view>
	</view>
</template>

<script>
	import {changeUserInfo} from '@/api/user/index.js'
	
	export default {
		data() {
			return {
				usernameData: {
					username: ''
				}
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: uni.getStorageSync('backgroundColor')
			})
		},
		methods: {
			submit() {
				changeUserInfo({
					username: this.usernameData.username
				}).then((res) => {
					if (res == null) {
						return
					}
					uni.setStorageSync("name", this.usernameData.username)
					uni.showToast({
						title: '修改成功',
						icon: 'success'
					});
				})
			}
		}
	}
</script>

<style>

</style>
